package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.RoadmapBigType;
import com.sailfish.springbootdemo.pojo.db1.RoadmapSmallType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface RoadmapSmallTypeDao {

    /**
     * 查询
     *
     * @param searchValue
     * @return
     */
    @Results(id = "roadmapSmallTypeResultMap", value = {
            @Result(column = "roadmap_small_type_id", property = "roadmapSmallTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "roadmap_big_type_id", property = "roadmapBigTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "roadmap_small_type_name", property = "roadmapSmallTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
    })
    @Select("<script>" +
            " select * from " + DB1TableName.ROADMAP_SMALL_TYPE + " where 1 = 1 " +
            "<if test='searchValue != null and searchValue != \"\" '>" +
            " and (roadmap_small_type_name like CONCAT('%',#{searchValue},'%'))" +
            "</if>" +
            "<if test='roadmapBigTypeId != null and roadmapBigTypeId != \"\" '>" +
            " and roadmap_big_type_id = #{roadmapBigTypeId} " +
            "</if>" +
            " order by sort" +
            "</script>")
    List<RoadmapSmallType> getAllRoadmapSmallType(@Param("searchValue") String searchValue, @Param("roadmapBigTypeId") Integer roadmapBigTypeId);


    @ResultMap(value = "roadmapSmallTypeResultMap")
    @Select("select * from " + DB1TableName.ROADMAP_SMALL_TYPE + " where roadmap_small_type_id = #{roadmapSmallTypeId}")
    RoadmapSmallType getRoadmapSmallTypeById(@Param("roadmapSmallTypeId") Integer roadmapSmallTypeId);

    /**
     * 删除
     *
     * @param roadmapSmallTypeId
     * @return
     */
    @Delete("delete from " + DB1TableName.ROADMAP_SMALL_TYPE + " where roadmap_small_type_id = #{roadmapSmallTypeId}")
    Integer deleteRoadmapSmallType(@Param("roadmapSmallTypeId") Integer roadmapSmallTypeId);

    /**
     * 新增
     *
     * @param roadmapSmallType
     * @return
     */
    @Insert("insert into " + DB1TableName.ROADMAP_SMALL_TYPE + "(roadmap_small_type_name,status,sort,create_time,roadmap_big_type_id) values " +
            "(#{roadmapSmallType.roadmapSmallTypeName},#{roadmapSmallType.status},#{roadmapSmallType.sort},#{roadmapSmallType.createTime},#{roadmapSmallType.roadmapBigTypeId})")
    Integer addRoadmapSmallType(@Param("roadmapSmallType") RoadmapSmallType roadmapSmallType);

    /**
     * 更新
     *
     * @param roadmapSmallType
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.ROADMAP_SMALL_TYPE +
            "<set>" +
            "<if test='roadmapSmallType.roadmapSmallTypeName != null and roadmapSmallType.roadmapSmallTypeName != \"\" '>" +
            " roadmap_small_type_name = #{roadmapSmallType.roadmapSmallTypeName}," +
            "</if>" +
            "<if test='roadmapSmallType.roadmapBigTypeId != null and roadmapSmallType.roadmapBigTypeId != \"\" '>" +
            " roadmap_big_type_id = #{roadmapSmallType.roadmapBigTypeId}," +
            "</if>" +
            "<if test='roadmapSmallType.updateTime != null '>" +
            " update_time = #{roadmapSmallType.updateTime}," +
            "</if>" +
            "<if test='roadmapSmallType.sort != null and roadmapSmallType.sort != \"\" '>" +
            " sort = #{roadmapSmallType.sort}," +
            "</if>" +
            "<if test='roadmapSmallType.status != null and roadmapSmallType.status != \"\" '>" +
            " status = #{roadmapSmallType.status}," +
            "</if>" +
            "</set>" +
            " where roadmap_small_type_id = #{roadmapSmallType.roadmapSmallTypeId}" +
            "</script>")
    Integer updateRoadmapSmallType(@Param("roadmapSmallType") RoadmapSmallType roadmapSmallType);
}
